<?
function lilina_user_main($args){
    extract ($args);
    if(!xarSecurityCheck('OverviewLilina')) return;
    xarVarFetch('startnum', 'id', $startnum, '1', XARVAR_NOT_REQUIRED, XARVAR_PREP_FOR_DISPLAY);
    xarVarFetch('catid', 'int', $data['catid'], '', XARVAR_NOT_REQUIRED, XARVAR_PREP_FOR_DISPLAY);
    xarVarFetch('hours', 'int', $hours, 24, XARVAR_NOT_REQUIRED);

    xarModAPIFunc('lilina',
                  'user',
                  'redirect');

    $timerange = ($hours ? $hours * 3600 : 3600 * 24);
    $links = xarModAPIFunc('lilina',
                           'user',
                           'getall_stories',
                            array('catid' => $data['catid'],
                                  'startnum' => $startnum,
                                  //'timerange' => $timerange,
                                  'numitems' => xarModGetVar('lilina', 'itemsperpage')));
    $data['pager'] = xarTplGetPager($startnum,
                                    xarModAPIFunc('lilina', 'user', 'countitems'),
                                    xarModURL('lilina', 'user', 'main', array('startnum' => '%%',
                                                                              'catid'    => $data['catid'],
                                                                              'hours'    => $hours)),
                                    xarModGetVar('lilina', 'itemsperpage'));

    for ($i = 0; $i < count($links); $i++) {
        $link = $links[$i];

        $links[$i]['comments'] = xarModAPIFunc('comments',
                                               'user',
                                               'get_count',
                                               array('modid' => xarModGetIDFromName('lilina'),
                                                     'objectid' => $link['id']));
        
        if (!$links[$i]['comments']) {
            $links[$i]['comments'] = '';
        } elseif ($links[$i]['comments'] == 1) {
            $links[$i]['comments'] .= ' ' . xarML('comment');
        } else {
            $links[$i]['comments'] .= ' ' . xarML('comments');
        }

        $links[$i]['keywords'] = xarModAPIFunc('keywords',
                                  'user',
                                  'getmultiplewords',
                                  array('modid' => xarModGetIDFromName('lilina'),
                                        'objectids' =>  array($link['id']),
                                        'itemtype'  => 1));




        $links[$i]['link'] = str_replace('&', '&amp;', $link['link']);
        $links[$i]['summary'] = xarModAPIFunc('lilina',
                              'user',
                              'garbage',
                              array('str' => $link['summary']));
        $links[$i]['title'] = xarModAPIFunc('lilina',
                              'user',
                              'garbage',
                              array('str' => $link['title']));
        $links[$i]['link'] = xarModAPIFunc('lilina',
                              'user',
                              'garbage',
                              array('str' => $link['link']));
        $links[$i]['title']    = xarVarPrepForDisplay(substr($link['title'], 0, 70));
        if (xarSecurityCheck('AdminLilina',0)) {
            $links[$i]['deleteurl'] = xarModURL('lilina',
                                                'admin',
                                                'add_garbage',
                                                array('id'      => $link['id'],
                                                      'unique'  => $link['unique']));
            $links[$i]['javascript'] = "return confirmLink(this, '" . xarML('Add to filtered content') . " $link[title] ?')";
        } 

         $text = $link['summary'];
         $text = preg_replace('/</',' <',$text);
         $text = preg_replace('/>/','> ',$text);
         $desc = html_entity_decode(strip_tags($text));
         $desc = preg_replace('/[\n\r\t]/',' ',$desc);
         $desc = preg_replace('/  /',' ',$desc);
        $links[$i]['summary'] = $desc;

         $text = $link['title'];
         $text = preg_replace('/</',' <',$text);
         $text = preg_replace('/>/','> ',$text);
         $desc = html_entity_decode(strip_tags($text));
         $desc = preg_replace('/[\n\r\t]/',' ',$desc);
         $desc = preg_replace('/  /',' ',$desc);
        $links[$i]['title'] = $desc;
    }
    $data['items'] = $links;
    return $data;
}
?>